*******************************************************************************
*** Data Analysis 
*** The political dynamics of portfolio design in European democracies
*** by 
*** Ulrich Sieberer, Thomas M. Meyer, Hanna Bäck, Andrea Ceron, 
*** Albert Falcó-Gimeno, Isabelle Guinaudeau, Martin Ejnar Hansen, 
*** Kristoffer Kolltveit, Tom Louwerse, Wolfgang C. Müller, Thomas Persson
*******************************************************************************

clear
clear mata 
clear matrix
version 14.0
set more off
set scrollbufsize 50000
set mem 512M, 
set scheme sj
set trace off
capture log close
* Load package from Ruhe 2016 (cited in the article)
net from http://www.stata-journal.com/software/sj16-4
net install st0458

*** Descriptive analysis: time between reforms (Table 2)
* load data
use "PD_reform_data.dta", clear


* Average time between two (major/relevant) reforms
bysort country (date_reform): gen datediff = abs(date_reform - date_reform[_n-1])
	label var datediff "Difference between two following changes (in days)"
summarize datediff if datediff!=., detail

* Table: mean time between reforms by country
preserve
collapse (mean) datediff, by(country)
sort country
replace datediff=round(datediff,.1)
rename datediff avg_time_by_country
list *
save  reform_by_country.dta, replace  
restore

* Table: mean time between reforms by country / by decade
preserve
gen year=year(date_reform)
gen decade=1970 if year>=1969 & year<=1979
replace decade=1980 if year>=1980 & year<=1989
replace decade=1990 if year>=1990 & year<=1999
replace decade=2000 if year>=2000 & year<=2015
drop if decade==.
bysort decade: sum datediff
collapse (mean) datediff, by( decade country)
replace datediff=round(datediff,.1)
rename datediff avg_time_by_decade_country
sort  country decade 
reshape wide avg_time_by_decade_country  , i(country) j(decade)
list *
save  reform_by_decade_country.dta, replace  
merge 1:1 country using "reform_by_country.dta"
drop _merge
format avg_* %9.1g
label var avg_time_by_decade_country1970 "1970s"
label var avg_time_by_decade_country1980 "1980s"
label var avg_time_by_decade_country1990 "1990s"
label var avg_time_by_decade_country2000 "2000s"
label var avg_time_by_country "Mean"
label var country "Country"
list * 
export excel  "reform_by_decade_country.xls", replace  firstrow(varlabels)
restore

erase reform_by_country.dta
erase reform_by_decade_country.dta



********************************************************************************
*** Duration analysis with time-varying covariates
use duration_data.dta, clear

* generate country & decade dummies
tab decade, gen(decade_)
tab country, gen(country_)

*stset data
stset t1, failure(failure) id(unique_id)

*** Test proportional hazards assumption
stcox  gov_change                                                      election_event  caretaker coalition law   wdi_unempne_change  i.decade    ,  nohr
estat phtest, rank detail 
stcox                pm_change                                         election_event  caretaker coalition law   wdi_unempne_change  i.decade    ,  nohr
estat phtest, rank detail 
stcox                           abs_cab_pos_change                     election_event  caretaker coalition law   wdi_unempne_change  i.decade    ,  nohr
estat phtest, rank detail 
stcox                                              abs_enp_gov_change  election_event  caretaker coalition law   wdi_unempne_change  i.decade    ,  nohr
estat phtest, rank detail 
stcox   gov_change pm_change    abs_cab_pos_change abs_enp_gov_change  election_event  caretaker  coalition law   wdi_unempne_change i.decade    ,  nohr
estat phtest, rank detail 



*** Estimate models with time-varying effects (Table 3)
stcox  gov_change                                                      election_event  caretaker coalition law   wdi_unempne_change  i.decade    , tvc(                                election_event law ) texp(ln(_t)) nohr
stcox                pm_change                                         election_event  caretaker coalition law   wdi_unempne_change  i.decade    , tvc(                     pm_change  election_event law ) texp(ln(_t)) nohr
stcox                           abs_cab_pos_change                     election_event  caretaker coalition law   wdi_unempne_change  i.decade    , tvc(                                election_event     ) texp(ln(_t)) nohr
stcox                                              abs_enp_gov_change  election_event  caretaker coalition law   wdi_unempne_change  i.decade    , tvc(                                election_event     ) texp(ln(_t)) nohr
stcox  gov_change  pm_change    abs_cab_pos_change abs_enp_gov_change  election_event  caretaker coalition law   wdi_unempne_change  i.decade    , tvc( abs_cab_pos_change  pm_change election_event law  ) texp(ln(_t)) nohr



*** Plot survival functions (Figure 1; Ruhe 2016)

* Survival curve for change in party composition
* other covs at mean & mode
scurve_tvc, generate(govshare_change_0) at(election_event 0 gov_change 0 pm_change 0 abs_enp_gov_change 0 abs_cab_pos_change 0 coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event     abs_cab_pos_change   pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(govshare_change_sd) at(election_event 0  gov_change 1  pm_change 0 abs_enp_gov_change 0   abs_cab_pos_change 0 coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change    pm_change law) texp(ln(_t)) replace

* until 95% percentile	
twoway  line govshare_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line govshare_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " ) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.05 1300 "Party change",size(small)) ///
	text(0.24 1400 "No change",size(small)) ///
	xsize(4) ysize(4) ///
	title("Δ Partisan composition of cabinet", color(black) size(medium))

graph save fig1a.gph, replace

* Predicted values after 365 days
sort _tscurve
list govshare_change_0 govshare_change_sd _tscurve  if   _tscurve==365 




* Survival curve for PM change
* other covs at mean & mode
scurve_tvc, generate(pm_1) at(election_event 0 gov_change 0 pm_change 1  abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0  ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event   abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(pm_0) at(election_event 0 gov_change 0  pm_change 0   abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event  abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace

	
* until 95% percentile	
twoway line pm_1  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line pm_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.25 1400 "No change",size(small)) ///
	text(0.07 1400 "PM change",size(small)) ///
	xsize(4) ysize(4) ///
	title("Δ Prime Minister", color(black) size(medium))
graph save fig1b.gph, replace

* Predicted values after 365 days
sort _tscurve
list pm_0 pm_1 _tscurve  if   _tscurve==365 



* Survival curve for change in cabinet policy position
* Note: gov_change should be 1 for a meaningful comparison
* other covs at mean & mode
scurve_tvc, generate(abs_cab_pos_change_0)  at(election_event 0 gov_change 1 pm_change 0   abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(abs_cab_pos_change_sd) at(election_event 0 gov_change 1  pm_change 0  abs_enp_gov_change 0   abs_cab_pos_change 0.845 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change    pm_change   law) texp(ln(_t)) replace

* until 95% percentile	
twoway line abs_cab_pos_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line abs_cab_pos_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.0 150 "No change",size(small)) ///
	text(0.13 350 "+1 SD",size(small)) ///
	xsize(4) ysize(4) ///
	title("|Δ cabinet policy position|", color(black) size(medium))
graph save fig1c.gph, replace

* Predicted values after 365 days
sort _tscurve
list abs_cab_pos_change_0 abs_cab_pos_change_sd _tscurve  if   _tscurve==365 



* Survival curve for change in ENP (gov)
* Note: gov_change should be 1 for a meaningful comparison
* other covs at mean & mode
scurve_tvc, generate(abs_enp_gov_change_0) at(election_event 0 gov_change 1 pm_change 0   abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(abs_enp_gov_change_sd) at(election_event 0 gov_change 1  pm_change 0  abs_enp_gov_change .330   abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event   abs_cab_pos_change    pm_change   law) texp(ln(_t)) replace

* until 95% percentile	
twoway line abs_enp_gov_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line abs_enp_gov_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability"  " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.0 150 "No change",size(small)) ///
	text(0.12 350 "+1 SD",size(small)) ///
	xsize(4) ysize(4) ///
	title("|Δ Effective no. of government parties|", color(black) size(medium))

graph save fig1d.gph, replace

* Predicted values after 365 days
sort _tscurve
list abs_enp_gov_change_0 abs_enp_gov_change_sd _tscurve  if   _tscurve==365


graph combine fig1a.gph  fig1b.gph  fig1c.gph  fig1d.gph  ,  graphregion(color(white))  
graph export "fig1.tif", replace width(2400)
erase fig1a.gph
erase fig1b.gph
erase fig1c.gph
erase fig1d.gph




*********************************************************************************
* Appendix B: Models with country FEs
*********************************************************************************
stcox  gov_change                                                      election_event  caretaker coalition law   wdi_unempne_change  i.decade   ib1.country_int , tvc(                                election_event law ) texp(ln(_t)) nohr
stcox                pm_change                                         election_event  caretaker coalition law   wdi_unempne_change  i.decade   ib1.country_int , tvc(                     pm_change  election_event law ) texp(ln(_t)) nohr
stcox                           abs_cab_pos_change                     election_event  caretaker coalition law   wdi_unempne_change  i.decade   ib1.country_int , tvc(                                election_event     ) texp(ln(_t)) nohr
stcox                                              abs_enp_gov_change  election_event  caretaker coalition law   wdi_unempne_change  i.decade   ib1.country_int , tvc(                                election_event     ) texp(ln(_t)) nohr
stcox  gov_change    pm_change  abs_cab_pos_change abs_enp_gov_change  election_event  caretaker coalition law   wdi_unempne_change  i.decade   ib1.country_int,  tvc( abs_cab_pos_change  pm_change  election_event law ) texp(ln(_t)) nohr



*** Plot survival functions (Figure B.1)
	
* Survival curve for partisan composition of cabinet
* other covs at mean & mode
scurve_tvc, generate(govshare_change_0) at(election_event 0 gov_change 0 pm_change 0 abs_enp_gov_change 0 abs_cab_pos_change 0 coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event     abs_cab_pos_change   pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(govshare_change_sd) at(election_event 0  gov_change  1  pm_change 0 abs_enp_gov_change 0   abs_cab_pos_change 0 coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change    pm_change law) texp(ln(_t)) replace

* until 95% percentile	
twoway  line govshare_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line govshare_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " ) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(-0.001 150 "Party change",size(small)) ///
	text(0.2 550 "No change",size(small)) ///
	xsize(4) ysize(4) ///
	title("Δ Partisan composition of cabinet", color(black) size(medium))

graph save fig1a_AppendixB.gph, replace



* Survival curve for PM change
* other covs at mean & mode
scurve_tvc, generate(pm_1) at(election_event 0 gov_change 0 pm_change 1  abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0  ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event   abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(pm_0) at(election_event 0 gov_change 0  pm_change 0   abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event  abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace

	
* until 95% percentile	
twoway line pm_1  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line pm_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.3 550 "No change",size(small)) ///
	text(0.0 150 "PM change",size(small)) ///
	xsize(4) ysize(4) ///
	title("Δ Prime minister", color(black) size(medium))
graph save fig1b_AppendixB.gph, replace



* Survival curve for change in cabinet policy position
* Note: gov_change should be 1 for a meaningful comparison
* other covs at mean & mode
scurve_tvc, generate(abs_cab_pos_change_0)  at(election_event 0 gov_change 1 pm_change 0   abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(abs_cab_pos_change_sd) at(election_event 0 gov_change 1  pm_change 0  abs_enp_gov_change 0   abs_cab_pos_change 0.845 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change    pm_change   law) texp(ln(_t)) replace

* until 95% percentile	
twoway line abs_cab_pos_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line abs_cab_pos_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.0 125 "No change",size(small)) ///
	text(0.13 350 "+1 SD",size(small)) ///
	xsize(4) ysize(4) ///
	title("|Δ cabinet policy position|", color(black) size(medium))

graph save fig1c_AppendixB.gph, replace




* Survival curve for change in ENP (gov)
* Note: gov_change should be 1 for a meaningful comparison
* other covs at mean & mode
scurve_tvc, generate(abs_enp_gov_change_0) at(election_event 0 gov_change 1 pm_change 0   abs_enp_gov_change 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event    abs_cab_pos_change     pm_change  law) texp(ln(_t)) replace
scurve_tvc, generate(abs_enp_gov_change_sd) at(election_event 0 gov_change 1  pm_change 0  abs_enp_gov_change .330   abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	country_1 0 country_2 0 country_3 1 country_4 0 country_5 0 country_6 0 country_7 0 country_8 0 country_9 0 ///
	wdi_unempne_change .066) ///
	tvc(election_event   abs_cab_pos_change    pm_change   law) texp(ln(_t)) replace

* until 95% percentile	
twoway line abs_enp_gov_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line abs_enp_gov_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability"  " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.0 125 "No change",size(small)) ///
	text(0.12 350 "+1 SD",size(small)) ///
	xsize(4) ysize(4) ///
	title("|Δ Effective no. of government parties|", color(black) size(medium))

graph save fig1d_AppendixB.gph, replace



graph combine fig1a_AppendixB.gph  fig1b_AppendixB.gph  fig1c_AppendixB.gph  fig1d_AppendixB.gph  ,  graphregion(color(white))  
graph export "fig_AppendixB.tif", replace width(2400)
erase fig1a_AppendixB.gph
erase fig1b_AppendixB.gph
erase fig1c_AppendixB.gph
erase fig1d_AppendixB.gph





*********************************************************************************
* Appendix C: Graphs for testing H1 - H4 in separate analyses 
*********************************************************************************

	
* Survival curve for change in party composition
* other covs at mean & mode
scurve_tvc, generate(govshare_change_0) at(election_event 0 gov_change 0   coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    law) texp(ln(_t)) replace
scurve_tvc, generate(govshare_change_sd) at(election_event 0  gov_change 1  coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    law) texp(ln(_t)) replace

* until 95% percentile	
twoway  line govshare_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line govshare_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " ) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.04 1300 "Party change",size(small)) ///
	text(0.22 1400 "No change",size(small)) ///
	xsize(4) ysize(4) ///
	title("∆ Partisan composition of cabinet", color(black) size(medium))

graph save fig1a_AppendixC.gph, replace


	
* Survival curve for change in party composition
* other covs at mean & mode
scurve_tvc, generate(pm_change_0) at(election_event 0 pm_change 0   coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event  pm_change   law) texp(ln(_t)) replace
scurve_tvc, generate(pm_change_1) at(election_event 0  pm_change 1  coalition 1  caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event  pm_change  law) texp(ln(_t)) replace

* until 95% percentile	
twoway  line pm_change_1  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line pm_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " ) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.04 1300 "PM Change",size(small)) ///
	text(0.2 1400 "No change",size(small)) ///
	xsize(4) ysize(4) ///
	title("Δ Prime minister", color(black) size(medium))

graph save fig1b_AppendixC.gph, replace



* Survival curve for change in cabinet policy position
* other covs at mean & mode
scurve_tvc, generate(abs_cab_pos_change_0)  at(election_event 0  abs_cab_pos_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event     ) texp(ln(_t)) replace
scurve_tvc, generate(abs_cab_pos_change_sd) at(election_event 0  abs_cab_pos_change 0.845 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event     ) texp(ln(_t)) replace

* until 95% percentile	
twoway line abs_cab_pos_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line abs_cab_pos_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability" " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.0 1300 "+1 SD",size(small)) ///
	text(0.2 1400 "No change",size(small)) ///
	xsize(4) ysize(4) ///
	title("|Δ cabinet policy position|", color(black) size(medium))

graph save fig1c_AppendixC.gph, replace



* Survival curve for change in ENP (gov)
* other covs at mean & mode
scurve_tvc, generate(abs_enp_gov_change_0) at(election_event 0   abs_enp_gov_change 0 coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    ) texp(ln(_t)) replace
scurve_tvc, generate(abs_enp_gov_change_sd) at(election_event 0  abs_enp_gov_change .330  coalition 1 caretaker 0 law 0 ///
	decade_1 0 decade_2 0 decade_3 0 decade_4 1 ///
	wdi_unempne_change .066) ///
	tvc(election_event    ) texp(ln(_t)) replace

* until 95% percentile	
twoway line abs_enp_gov_change_sd  _tscurve if _tscurve<=1422,  lpattern(dash) ///
	|| line abs_enp_gov_change_0  _tscurve if _tscurve<=1422,  lpattern(solid) ///
	xtitle("Time in days", size(small)) ytitle("Porfolio design stability"  " " , size(medsmall)) ///
	ylabel(0(0.2)1, nogrid labsize(small)) ///
	xscale(range(0 1550)) ///
	xlabel(, labsize(small)) ///
	graphregion(color(white)) ///
	legend(off) ///
	text(0.01 1300 "+1 SD",size(small)) ///
	text(0.18 1400 "No change",size(small)) ///
	xsize(4) ysize(4) ///
	title("|Δ Effective no. of government parties|", color(black) size(medium))

graph save fig1d_AppendixC.gph, replace


graph combine fig1a_AppendixC.gph  fig1b_AppendixC.gph  fig1c_AppendixC.gph  fig1d_AppendixC.gph  ,  graphregion(color(white))  
graph export "fig1_AppendixC.tif", replace width(2400)
erase fig1a_AppendixC.gph
erase fig1b_AppendixC.gph
erase fig1c_AppendixC.gph
erase fig1d_AppendixC.gph



